{	Problem: http://codechef.com/problems/TPRODUCT/
 	Verdict: Accepted
}
const md=1000000007;
 
var
	n,i,k,ind,x:longint;
	a:array[0..40000] of longint;
	b:array[0..40000] of double;
	s,m:double;
	r:int64;
begin
read(n);
while n>0 do begin
	k:=1 shl n-1;
	for i:=1 to k do begin
		read(a[i]);
		b[i]:=ln(a[i]);
	end; 
	m:=-maxlongint;
	ind:=k;
	for i:=1 shl (n-1) to k do begin
		s:=b[i];
		x:=i shr 1;
		while x>0 do begin
			s:=s+b[x];
			x:=x shr 1;
		end;
		if s>m then begin
			m:=s;
			ind:=i;
		end;
	end;
	r:=a[ind];
	ind:=ind shr 1;
	while ind>0 do begin
		r:=(r*a[ind]) mod md;
		ind:=ind shr 1;
	end;
	writeln(r);
	read(n);
end;
end.